package com.card.game;

import java.util.List;
import java.util.Set;
import java.util.Vector;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

/**   
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author siyunlong  
 * @date 2016年12月12日 下午7:07:14 
 * @version V1.0   
 */
public class YzUtils {
//	public static final ImmutableList<Card> FengCards = ImmutableList
//			.of(new Card(4,0),new Card(5,0),new Card(6,0),new Card(7,0),new Card(8,1),new Card(8,2),new Card(8,3));
	public static final List<Card> FengGang = Lists.newArrayList(new Card(4,0),new Card(5,0),new Card(6,0),new Card(7,0));
	public static final List<Card> JianCard = Lists.newArrayList(new Card(CardType.Jian,1),new Card(CardType.Jian,2),new Card(CardType.Jian,3));

	public static List<Card> getFengOutCardForTing(Vector<Card> sour) {
		Vector<Card> cards = (Vector<Card>)sour.clone();
		List<Card> outs = Lists.newArrayList();
		//====================
		for (Card card : JianCard) {
			cards.remove(card);
		}
		cards = KdUtils.transCards(cards);
		if(HandUtils.isHuPai(cards)) {
			outs.addAll(JianCard);
		}
		//====================
		Set<Card> setCard = Sets.newHashSet();
		for (int i = 0; i < cards.size(); i++) {
			Vector<Card> clone = (Vector<Card>)cards.clone();
			Card c = clone.remove(i);
			if(setCard.contains(c)) continue;
			if(KdUtils.isCanTingForCard(clone)) {
				outs.add(c);
			}
			setCard.add(c);
		}
		setCard.clear();
		KdUtils.fanTransCards(outs);
		Set<Card> ccs = Sets.newHashSet(outs);
		return Lists.newArrayList(ccs);
	}
	
	public static List<Card> getFengOutCardForTing(Vector<Card> cards,Card niuCard) {
		List<Card> outs = Lists.newArrayList();
		Set<Card> setCard = Sets.newHashSet();
		for (int i = 0; i < cards.size(); i++) {
			Vector<Card> clone = (Vector<Card>)cards.clone();
			Card c = clone.remove(i);
			if(setCard.contains(c)) continue;
			if(KdUtils.isHu(clone,niuCard)) {
				outs.add(c);
			}
			setCard.add(c);
		}
		setCard.clear();
		return outs;
	}
	private static boolean isHuJian(Vector<Card> cards,Card temp) {
		Vector<Card> clone = (Vector<Card>)cards.clone();
		clone.add(temp);
		for (Card card : JianCard) {
			clone.remove(card);
		}
		clone = KdUtils.transCards(clone);
		return HandUtils.isHuPai(clone);
	}
	
	public static List<Card> getLackFengCard(Vector<Card> cards) {
		Vector<Card> sour = (Vector<Card>)cards.clone();
		List<Card> lackCards = Lists.newArrayList();
		for (Card card : YzUtils.JianCard) {
			if(!sour.contains(card)){
				lackCards.add(card);
				if(lackCards.size()>=2) return lackCards;
			}
		}
		return lackCards;
	}
	
//	public static void removeFengGang(Vector<Card> cards) {
//		while(cards.containsAll(FengGang)) {
//			for (Card card : FengGang) {
//				cards.remove(card);
//			}
//		}
//	}
	
	public static void main(String[] args) {
		String source = "11-1;11-2;11-3;11-1;11-2;11-3;2-9;2-9;";
		Vector<Card> cards = CardUtils.createCardsFromStr(source);
		List<Card> tings = YzUtils.getFengOutCardForTing(cards);
		for (Card card : tings) {
			System.err.println(card.toString());
		}
	}
}
